﻿using System;
using System.Diagnostics;


public abstract class Shape
{
    public abstract double CalculateArea();
    public abstract bool check();
}

public class Rectangle : Shape
{
    private int lenth { get; set; }
    private int width { get; set; }
    public Rectangle(int lenth, int width)
    {
        if (lenth < 0 || width < 0) throw new ArgumentException();
        this.lenth = lenth;
        this.width = width;
    }

    public override double CalculateArea()
    {
        return lenth * width;
    }
    public override bool check()
    {
        if (lenth > 0 && width > 0) return true;
        return false;
    }
}

public class Square : Shape
{
    private int lenth { get; set; }
    public Square(int lenth)
    {
        this.lenth = lenth;
    }

    public override double CalculateArea()
    {
        return lenth * lenth;
    }
    public override bool check()
    {
        if (lenth > 0) return true;
        return false;
    }
}

public class Triangle : Shape
{

    private int a1 { get; set; }
    private int a2 { get; set; }
    private int a3 { get; set; }
    public Triangle(int a1, int a2, int a3)
    {
        this.a1 = a1;
        this.a2 = a2;
        this.a3 = a3;
    }
    public override double CalculateArea()
    {
        double p = (double)(a1 + a2 + a3) / 2;
        double ans = p * (p - a1) * (p - a2) * (p - a3);
        return Math.Sqrt(ans);
    }

    public override bool check()
    {
        if (a1 + a2 > a3 && a1 + a3 > a2 && a2 + a3 > a1 && a1 > 0 && a2 > 0 && a3 > 0) return true;
        return false;
    }
}

public class Factory
{
    public static Shape GetShape(string name, int a, int b, int c)
    {
        Shape shape = null;
        switch (name)
        {
            case "Rectangle":
                shape = new Rectangle(a, b);
                break;
            case "Square":
                shape = new Square(a);
                break;
            case "Triangle":
                shape = new Triangle(a, b, c);
                break;
            default:
                break;
        }
        return shape;
    }
}
public class ConsoleApp1
{
    public static void Main(string[] args)
    {
        string[] s = new string[] { "Rectangle" , "Square" , "Triangle" };
        int a = 0, b = 0, c = 0;
        string tmp;
        double sum = 0;
        for (int i = 0; i < 10; )
        {
            
            
            //创建Random对象
            Random r = new Random();
            int name = r.Next(3);
            int result;
            switch (s[name])
            {
                case "Rectangle":
                    result = r.Next(1000);
                    a=result;
                    result = r.Next(1000);
                    b=result;
                    c = 0;
                    break;
                case "Square":
                    result=r.Next(1000);
                    a= result;
                    b = 0;
                    c = 0;
                    break;
                case "Triangle":
                    result =r.Next(1000);
                    a= result;
                    result= r.Next(1000);
                    b= result;
                    result = r.Next(1000);
                    c = result;
                    break;
                default:
                    break;
            }
            Shape shape = Factory.GetShape(s[name], a, b, c);
            if (shape.check())
            {
                Console.WriteLine(s[name] + ":" + shape.CalculateArea() + "\n");
                sum += shape.CalculateArea();
                i++;
            }
        }
        Console.WriteLine("面积之和是" + sum);
    }
}
